package o;

import android.text.TextUtils;
import androidx.annotation.NonNull;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map.Entry;
import java.util.concurrent.CountDownLatch;
import o.ftz.e;
import o.fus.a;

public class erp implements sg<InputStream> {
    private IOException ʻ = null;
    private volatile ftz ˊ;
    private final e ˋ;
    private InputStream ˎ;
    private final ve ˏ;
    private fuy ॱ;

    public erp(e eVar, ve veVar) {
        this.ˋ = eVar;
        this.ˏ = veVar;
    }

    public void ˏ(@NonNull rl rlVar, @NonNull d<? super InputStream> dVar) {
        erj.ॱ().ˋ(this.ˏ.ˊ());
        a ˎ = new a().ˎ(this.ˏ.ˊ());
        for (Entry entry : this.ˏ.ˏ().entrySet()) {
            ˎ.ˋ((String) entry.getKey(), (String) entry.getValue());
        }
        ˎ.ˋ("Connection", "Keep-Alive");
        ˎ.ˋ("User-Agent", ˊ());
        this.ˊ = this.ˋ.ˎ(ˎ.ॱ());
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        this.ˊ.enqueue(new fua(this) {
            final /* synthetic */ erp ˋ;

            public void onFailure(ftz o_ftz, IOException iOException) {
                this.ˋ.ʻ = iOException;
                countDownLatch.countDown();
                if (!(o_ftz == null || o_ftz.isCanceled())) {
                    Logger.e("OkHttpGlideFetcher", this.ˋ.ˏ.ˊ());
                }
                erj.ॱ().ॱ(this.ˋ.ˏ.ˊ());
            }

            public void onResponse(ftz o_ftz, fvb o_fvb) throws IOException {
                this.ˋ.ॱ = o_fvb.ᐝ();
                if (!o_fvb.ˏ()) {
                    this.ˋ.ʻ = new IOException("Request failed with code: " + o_fvb.ˊ());
                    if (!(o_ftz == null || o_ftz.isCanceled())) {
                        Logger.e("OkHttpGlideFetcher", this.ˋ.ˏ.ˊ() + " ,onResponse code: " + o_fvb.ˊ());
                    }
                }
                countDownLatch.countDown();
                erj.ॱ().ˏ(this.ˋ.ˏ.ˊ());
            }
        });
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            if (Logger.ˎ()) {
                Logger.ˏ("OkHttpGlideFetcher", "InterruptedException:" + e.toString());
            }
        }
        if (this.ʻ != null) {
            if (Logger.ˎ()) {
                Logger.ˏ("OkHttpGlideFetcher", "InterruptedException:" + this.ʻ.toString());
            }
            dVar.ˏ(this.ʻ);
            return;
        }
        this.ˎ = aak.ˊ(this.ॱ.ˎ(), this.ॱ.ˏ());
        dVar.ॱ(this.ˎ);
    }

    @NonNull
    public Class<InputStream> ˋ() {
        return InputStream.class;
    }

    @NonNull
    public rz ˎ() {
        return rz.ॱ;
    }

    public void ˏ() {
        dnw.ˎ(this.ˎ);
        dnw.ˎ(this.ॱ);
    }

    public void ॱ() {
        ftz o_ftz = this.ˊ;
        if (o_ftz != null) {
            o_ftz.cancel();
        }
    }

    private String ˊ() {
        String ˎ = epb.ˎ();
        if (TextUtils.isEmpty(ˎ)) {
            return "Android/1.0";
        }
        return ˎ;
    }
}
